package com.dpj.nio.c1;

import java.nio.ByteBuffer;

public class TestByteBufferRead {
    public static void main(String[] args) {
        ByteBuffer buffer=ByteBuffer.allocate(10);
        buffer.put(new byte[]{'a','b','c','d'});
        buffer.flip();
        // rewind 从头开始读
//        buffer.get(new byte[4]);
//        ByteBufferUtil.debugAll(buffer);
//
//        buffer.rewind();
//        ByteBufferUtil.debugAll(buffer);
//        System.out.println(buffer.get());

        //mark & reset
        //mark 做一个标记,记录position位置，reset是将position 重置到mark位置
     /*   System.out.println((char)buffer.get());
        System.out.println((char)buffer.get());
        buffer.mark(); //加标记 索引为2的位置
        System.out.println((char)buffer.get());
        System.out.println((char)buffer.get());
        buffer.reset();
        System.out.println((char)buffer.get());
        System.out.println((char)buffer.get());

      */
        //get(i) 不会改变索引位置
        System.out.println(buffer.get(3));

        ByteBufferUtil.debugAll(buffer);


    }
}
